package FrameWork.World.Util;

/**
 * 计时器
 */
public class StopWatch {

    private long period;
    private long lastTime;

    public StopWatch(long period){
        this.period = period;
        this.lastTime = TimeUtil.getCurrentTimeMill();
    }

    public boolean hasTimeOut(){
        long curr = TimeUtil.getCurrentTimeMill();
        if (curr-lastTime>=period){
            lastTime = curr;
            return true;
        }
        return false;
    }

    public long getRemainTime(){
        long curr = TimeUtil.getCurrentTimeMill();
        long remain = curr-this.lastTime;
        return remain>0? remain: 0;
    }

    public long getPeriod() {
        return period;
    }

    public long getLastTime() {
        return lastTime;
    }

    public void reset(){
        this.lastTime = TimeUtil.getCurrentTimeMill();
    }

    public void reset(long t){
        this.lastTime = t;
    }
}
